package com.lc.user.express.httpserver;

import android.text.TextUtils;

import com.lc.user.express.model.AddrModel;
import com.lc.user.express.model.FurnitureModel;
import com.lc.user.express.utils.PublicMethod;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/31. 路线详情
 */
@HttpInlet(Net.GET_ADDR_INFO)
public class GetAddrInfo extends ZJDBAsyGet<GetAddrInfo.Info> {
    public String userid;
    public String id;

    public GetAddrInfo(String userid,String id,AsyCallBack listener) {
        super(listener);
        this.userid = userid;
        this.id = id;

    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            JSONArray array = object.optJSONArray("list");

            if(array != null){
                for (int i = 0; i<array.length(); i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    AddrModel model = new AddrModel();
                    model.setName(jsonObject.optString("name"));
                    model.setMobile(jsonObject.optString("mobile"));
                    model.setAddr(jsonObject.optString("address"));
                    model.setPoint(jsonObject.optString("point"));
                    if(!TextUtils.isEmpty(jsonObject.optString("point"))){
                        String[] s = jsonObject.optString("point").split(",");
                        model.setLng(PublicMethod.strToDouble(s[1]));
                        model.setLat(PublicMethod.strToDouble(s[0]));
                    }
                    info.dataList.add(model);
                }

            }
            return info;
        }
        return null;
    }

    public static class Info {
        public List<AddrModel> dataList = new ArrayList<>();
    }
}
